package state;

public class KeyRepeatHandle extends GameControl {
  private int startTime = 0;
  private boolean isKeyActive = false;
  private int currentKeyCode = 0;

  private SystemCanvas systemCanvas = null;

  public KeyRepeatHandle(SystemCanvas systemCanvas1) {
    this.systemCanvas = systemCanvas1;
    setTimeInterval(30);
    setRepeat(true);
  }

  public void perform() {
    if (isKeyActive) {
      systemCanvas.doKeyRepeated(currentKeyCode);
    }
  }

  public void keyPressed(int keyCode) {
    currentKeyCode = keyCode;
    startTime = (int) System.currentTimeMillis();
    isKeyActive = true;
  }

  public void keyReleased() {
    isKeyActive = false;
  }

  public int getKeyRepeatStartTime() {
    return startTime;
  }

  public void cancel() {
    stop();
  }

  public int getDelay() {
    return getTimeInterval();
  }

  public void serDelay(int sleepTime) {
    setTimeInterval(sleepTime);
  }

  public void resetDelay() {
    setTimeInterval(30);
  }
}
